import pokemon
import turnInfo
import random


tbox='blank'
pokemon.dataInitialized = False

class Player:
    
    def __init__(self, pos, add = 0):
        self.pos = pos
        if(pos == 0):
            self.pokemon = [pokemon.Pokemon(add[0]), pokemon.Pokemon(add[1]), pokemon.Pokemon(add[2]), pokemon.Pokemon(add[3]), pokemon.Pokemon(add[4]), pokemon.Pokemon(add[5])]
        else:
            toPass = [[], [], [], [], [], []]
            k = 1
            for n in range(0, 6):
                for j in range(0, 5):
                    toPass[n].append(add[k])
                    k += 1
            self.pokemon = [pokemon.Pokemon(toPass[0]), pokemon.Pokemon(toPass[1]), pokemon.Pokemon(toPass[2]), pokemon.Pokemon(toPass[3]), pokemon.Pokemon(toPass[4]), pokemon.Pokemon(toPass[5])]
        self.activePoke = 0
        
    def setActivePoke(self, newActive):
        self.activePoke = newActive
        tbox.addMessage(22, self.pokemon[self.activePoke].name)
        
    def reset(self):
        for n in self.pokemon:
            n.reset()
        self.activePoke = 0
        
    def newTeam(self, add):
        toPass = [[], [], [], [], [], []]
        k = 1
        for n in range(0, 6):
            for j in range(0, 5):
                toPass[n].append(add[k])
                k += 1
        self.pokemon = [pokemon.Pokemon(toPass[0]), pokemon.Pokemon(toPass[1]), pokemon.Pokemon(toPass[2]), pokemon.Pokemon(toPass[3]), pokemon.Pokemon(toPass[4]), pokemon.Pokemon(toPass[5])]
        self.activePoke = 0
        
    def chooseAction(self):
        #return turnInfo.TurnInfo(2, random.randrange(0, 6))
        return turnInfo.TurnInfo(1, random.randrange(0, 4))
    
    def chooseNewPoke(self):
        while 1:
            n = random.randrange(0, 6)
            if(self.pokemon[n].checkAlive()):
                return turnInfo.TurnInfo(2, n)
    
    def checkLivingPokemon(self):
        livingCounter = 0
        for n in range(0, 6):
            if(self.pokemon[n].checkAlive()):
                livingCounter += 1
        return livingCounter